﻿#!/usr/bin/python
# coding=utf-8

"""
Created on Fri Jan 17 20:39:01 2020

@author: Griza-pc
"""
import sys
import os 
import datetime,time 
import getpass		#输入密码时隐藏密码
import hashlib
import re	# 正则表达

#from tkinter import Tk
#from tkinter import filedialog as Filedialog
#root_win = Tk()
#root_win.withdraw()

import binascii as BAscii

try:
	from Crypto.Cipher import AES		#AES加密依赖的库
except Exception as e:
	os.system('pip install pycryptodome')
	os.system('pip install crypto')
	from crypto.Cipher import AES		#AES加密依赖的库

#最大窗口宽度
WIN_WRITE = 60
ADMIN_ACCOUNT = {} #管理员信息
ALL_ACCOUNT = {} #密码本信息
ADMINPASS = '' #储存登录密码,后面用作密码加密的key
isChance = False
MODE_OP = 0 	#编辑操作模式,0普通操作模式,1表示快捷操作模式

#加载密码本
def readPASS():
	for line in open(__file__,'r',encoding = 'utf-8'):
		if line[0:5] == '#-#-#':
			oneAcc = {}
			acc = line.rstrip('\n').split(' ')
			if len(acc) != 7:
				continue
			oneAcc['Explain'] = str(acc[1])
			oneAcc['Account'] = acc[2]
			oneAcc['Pass'] = acc[3]
			oneAcc['OldPass'] = acc[4]
			oneAcc['UpdateTime'] = acc[5]
			oneAcc['CreatTime'] = acc[6]
			ALL_ACCOUNT[acc[1]] = oneAcc
		if line[0:5] == '#-A-#':
			acc = line.rstrip('\n').split(' ')
			ADMIN_ACCOUNT['Explain'] = str(acc[1])
			ADMIN_ACCOUNT['Account'] = acc[2]
			ADMIN_ACCOUNT['Pass'] = acc[3]
			ADMIN_ACCOUNT['OldPass'] = acc[4]
			ADMIN_ACCOUNT['UpdateTime'] = acc[5]
			ADMIN_ACCOUNT['CreatTime'] = acc[6]
	return len(ALL_ACCOUNT)

def readOtherPass(filename):
	
	oth_ALL_account = {}
	oth_ADMIN_account = {}
	for line in open(filename,'r',encoding = 'utf-8'):
		if line[0:5] == '#-#-#':
			oneAcc = {}
			acc = line.rstrip('\n').split(' ')
			if len(acc) != 7:
				continue
			oneAcc['Explain'] = str(acc[1])
			oneAcc['Account'] = acc[2]
			oneAcc['Pass'] = acc[3]
			oneAcc['OldPass'] = acc[4]
			oneAcc['UpdateTime'] = acc[5]
			oneAcc['CreatTime'] = acc[6]
			oth_ALL_account[acc[1]] = oneAcc
		if line[0:5] == '#-A-#':
			acc = line.rstrip('\n').split(' ')
			oth_ADMIN_account['Explain'] = str(acc[1])
			oth_ADMIN_account['Account'] = acc[2]
			oth_ADMIN_account['Pass'] = acc[3]
			oth_ADMIN_account['OldPass'] = acc[4]
			oth_ADMIN_account['UpdateTime'] = acc[5]
			oth_ADMIN_account['CreatTime'] = acc[6]
	return oth_ADMIN_account,oth_ALL_account

#数据落盘
def saveAllPASS():
	try:
		file_data = ''
		for line in open(__file__,'r',encoding = 'utf-8'):
			if line[0:5] not in ('#-#-#','#-A-#'):
				file_data +=line
			else:
				break;
		file_data += '#-A-# %s %s %s %s %s %s\n'%(ADMIN_ACCOUNT['Explain'],
			ADMIN_ACCOUNT['Account'],
			ADMIN_ACCOUNT['Pass'],
			ADMIN_ACCOUNT['OldPass'],
			ADMIN_ACCOUNT['UpdateTime'],
			ADMIN_ACCOUNT['CreatTime'])
		for key in ALL_ACCOUNT.keys():
			file_data += '#-#-# %s %s %s %s %s %s\n'%(ALL_ACCOUNT[key]['Explain'],
				ALL_ACCOUNT[key]['Account'],
				ALL_ACCOUNT[key]['Pass'],
				ALL_ACCOUNT[key]['OldPass'],
				ALL_ACCOUNT[key]['UpdateTime'],
				ALL_ACCOUNT[key]['CreatTime'])
		with open(__file__,'w',encoding='utf-8') as f:
			f.write(file_data)
		return True
	except Exception as e:
		return False
	

def print_format(string,way,width,fill= ' ',ed = ''):
	'''
	中文英文字符创以指定宽度输出
	格式输出函数,默认格式填充用单空格,不换行。
	'''

	count = 0 #长宽度中文字符数量
	for word in string:#检测长宽度中文字符
		if (word >='\u4e00' and word <= '\u9fa5') or word in ['；','：','，','（','）','！','？','——','……','、','》','《']:
			count+=1
	width = width-count if width>=count else 0
	print('{0:{1}{2}{3}}'.format(string,fill,way,width),end = ed,flush=True)


def showSomePASS(some_account = ''):
	'''
	展示密码本
	'''
	if ADMINPASS == '':
		for i in range(10):
			print('非法查看!')
			time.sleep(1)
		return
	#print('{1:{0}<10}\t{2:{0}<10}\t{3:{0}<10}\t{4:{0}<10}\t{5:{0}<8}\t{6:{0}<8}'.format(chr(12288),'账号说明','账号','密码','旧密码','修改时间','创建时间'))	
	print('+{:-^133}+'.format(''))
	print('| ',end='')
	print_format('账号说明','<',20,' ')
	print(' | ',end='')
	print_format('账号','<',32,' ')
	print(' | ',end='')
	print_format('密码','<',16,' ')
	print(' | ',end='')
	print_format('旧密码','<',16,' ')
	print(' | ',end='')
	print_format('修改时间','<',16,' ')
	print(' | ',end='')
	print_format('创建时间','<',16,' ')
	print(' |',end='\n')
	print('+{:=^133}+'.format(''))

	for key in some_account.keys():
		one_pass = ''
		one_opass = ''
		#try:
		one_pass = decrypt(str(ADMINPASS),str(some_account[key]['Pass']))
		one_opass = decrypt(str(ADMINPASS),str(some_account[key]['OldPass']))
		#except exception as e:
			#print(str(adminpass)+'-----'+str(some_account[key]['pass']))
		#	print('密文出错!')
		#	time.sleep(2)
		#	return
		print('| ',end='')
		print_format(some_account[key]['Explain'],'<',20,' ')
		print(' | ',end='')
		print_format(some_account[key]['Account'],'<',32,' ')
		print(' | ',end='')
		print_format(one_pass,'<',16,' ')
		print(' | ',end='')
		print_format(one_opass,'<',16,' ')
		print(' | ',end='')
		print_format(some_account[key]['UpdateTime'],'<',16,' ')
		print(' | ',end='')
		print_format(some_account[key]['CreatTime'],'<',16,' ')
		print(' |',end='\n')
		print('+{:-^133}+'.format(''))
	
	#if some_account =='':
	#	some_account = ALL_ACCOUNT.copy()

	#table_acc = Texttable()
	#table_acc.set_cols_dtype(['t','t','t','t','t','t'])
	#table_acc.set_cols_width([20,20,20,20,16,16])

	#rows = []
	#rows.append(['账号说明','账号','密码','旧密码','修改时间','创建时间'])
	#for key in some_account.keys():
	#	one_pass = ''
	#	one_opass = ''
	#	try:
	#		one_pass = decrypt(str(ADMINPASS),str(some_account[key]['Pass']))
	#		one_opass = decrypt(str(ADMINPASS),str(some_account[key]['OldPass']))
	#	except Exception as e:
	#		#print(str(ADMINPASS)+'-----'+str(some_account[key]['Pass']))
	#		print('密文出错!')
	#		time.sleep(2)
	#		return
	#	rows.append([some_account[key]['Explain'],str(some_account[key]['Account']),one_pass,one_opass,some_account[key]['UpdateTime'],some_account[key]['CreatTime']])
	#table_acc.add_rows(rows)
	#print(table_acc.draw())

def appendPASS(in_data = ''):
	'''
	添加密码本
	'''
	while True:
		if MODE_OP == 0:
			in_data = input('输入账号描述 账号 密码，退出输入q:').split(' ')
		if in_data[0] == 'q':
			break
		elif len(in_data) != 3:
			continue
		else:
			#判断是否重复
			if in_data[0] in ALL_ACCOUNT.keys():
				print(str(in_data[0])+' have been in existence!')
				if MODE_OP == 1:
					break
				continue
			oneAcc = {}
			oneAcc['Explain'] = in_data[0]
			oneAcc['Account'] = in_data[1]
			oneAcc['Pass'] = encrypt(ADMINPASS,in_data[2])
			oneAcc['OldPass'] = encrypt(ADMINPASS,'NULL')
			oneAcc['UpdateTime'] = datetime.datetime.now().strftime("%Y/%m/%d/%H:%M")
			oneAcc['CreatTime'] = datetime.datetime.now().strftime("%Y/%m/%d/%H:%M")
			ALL_ACCOUNT[in_data[0]] = oneAcc
			saveAllPASS()
			if in_data[0] in ALL_ACCOUNT.keys():
				print('save success!')
				time.sleep(1)
				break
def delOnePASS(str_t):
	'''
	删除密码本
	'''
	if str_t == '':
		showSomePASS(ALL_ACCOUNT)
	while True:
		if str_t == '':
			str_t = str(input('输入完整账号说明(退出输入"q"):'))
		#判断是否存在
		if str_t == 'q':
			break 
		elif str_t not in ALL_ACCOUNT.keys():
			print('The has no the Explain!')
			continue
		else:
			if input('确定删除%s(y/n)'%(str_t)) == 'y':
				del ALL_ACCOUNT[str_t]
				saveAllPASS()
				if str_t not in ALL_ACCOUNT.keys():
					print('Del success!')
					time.sleep(2)
			break
def update_pass(str_t = '',in_data = ''):
	'''
	修改密码本
	'''
	if str_t == '' or in_data == '':
		showSomePASS(ALL_ACCOUNT)
	while True:
		if str_t == '':
			str_t = str(input('输入完整账号说明(退出输入"q"):'))
		#判断是否存在
		if str_t == 'q':
			break 
		elif str_t not in ALL_ACCOUNT.keys():
			print('The has no the Explain!')
			continue
		else:
			
			if in_data == '':
				print('修改账户-密码(%s-%s)'%(ALL_ACCOUNT[str_t]['Account'],ALL_ACCOUNT[str_t]['Pass']))
				in_data = input('输入新的账号以及密码(ex:admin pass),退出输入"q,').split(' ')
			if str_t == 'q':
				break
			o_pass = ALL_ACCOUNT[str_t]['Pass']
			ALL_ACCOUNT[str_t]['Account'] = in_data[0]
			ALL_ACCOUNT[str_t]['Pass'] = encrypt(ADMINPASS,in_data[1])
			ALL_ACCOUNT[str_t]['OldPass'] = o_pass
			ALL_ACCOUNT[str_t]['UpdateTime'] = datetime.datetime.now().strftime("%Y/%m/%d/%H:%M")
			saveAllPASS()
			if o_pass == ALL_ACCOUNT[str_t]['OldPass']:
				print('update success!')
				time.sleep(1)
				break
def mergePASS(filename):	
	'''
	合并密码本
	'''
	global ALL_ACCOUNT
	if not os.path.exists(filename):
		print('文件不存在!')
		return
	OTH_ADMIN_ACCOUNT,OTH_ALL_ACCOUNT = readOtherPass(filename)
	OTH_ADMINPASS = ''
	if OTH_ADMIN_ACCOUNT['Pass'] != ADMIN_ACCOUNT['Pass']:
		#两文件密码不一致
		while True:
			str_input = str(getpass.win_getpass('输入%s文件的密码(摁q键退出):'%(filename)))
			if str_input == 'q':
				return
			if(OTH_ADMIN_ACCOUNT['Pass'] != anaysisAdminPass(str_input)):
				print("密码错误！" + OTH_ADMIN_ACCOUNT['Pass'] +" "+ anaysisAdminPass(str_input))
			OTH_ADMINPASS = str_input
			break
			
		#需要经过解密再加密

		for key_oth in OTH_ALL_ACCOUNT.keys():
			isNeedMerageTheAcc = False

			#判断是否需要合并，当当前的密码本无此账号或者密码的不一样时需要合并。
			if key_oth not in ALL_ACCOUNT.keys():
				isNeedMerageTheAcc = True
			else:
				if decrypt(OTH_ADMINPASS,OTH_ALL_ACCOUNT[key_oth]['Pass']) !=  decrypt(ADMINPASS,ALL_ACCOUNT[key_oth]['Pass']):
					if datetime.datetime.strptime(OTH_ALL_ACCOUNT[key_oth]['UpdateTime'],"%Y/%m/%d/%H:%M") > datetime.datetime.strptime(ALL_ACCOUNT[key_oth]['UpdateTime'],"%Y/%m/%d/%H:%M"):
						print('检测到%s文件中的密码不一样,优先选择最近修改的密码! 即' + OTH_ALL_ACCOUNT[key_oth]['UpdateTime'])
						isNeedMerageTheAcc = True

			if isNeedMerageTheAcc:
				print(OTH_ALL_ACCOUNT[key_oth])
				oneAcc = {}
				oneAcc['Explain'] = OTH_ALL_ACCOUNT[key_oth]['Explain']
				oneAcc['Account'] = OTH_ALL_ACCOUNT[key_oth]['Account']
				oneAcc['Pass'] = encrypt(ADMINPASS,decrypt(OTH_ADMINPASS,OTH_ALL_ACCOUNT[key_oth]['Pass']))
				oneAcc['OldPass'] = encrypt(ADMINPASS,decrypt(OTH_ADMINPASS,OTH_ALL_ACCOUNT[key_oth]['OldPass']))
				oneAcc['UpdateTime'] = OTH_ALL_ACCOUNT[key_oth]['UpdateTime']
				oneAcc['CreatTime'] = OTH_ALL_ACCOUNT[key_oth]['CreatTime']
				ALL_ACCOUNT[key_oth] = oneAcc
			
	else:
		#两文件密码一致时 不重新解密加密
		OTH_ADMINPASS = ADMINPASS 
		for key_oth in OTH_ALL_ACCOUNT.keys():
			if key_oth not in ALL_ACCOUNT.keys():
				ALL_ACCOUNT[key_oth] = OTH_ALL_ACCOUNT[key_oth]
			else:
				if ALL_ACCOUNT[key_oth]['Pass'] != OTH_ALL_ACCOUNT[key_oth]['Pass']:
					if datetime.datetime.strptime(OTH_ALL_ACCOUNT[key_oth]['UpdateTime'],"%Y/%m/%d/%H:%M") > datetime.datetime.strptime(ALL_ACCOUNT[key_oth]['UpdateTime'],"%Y/%m/%d/%H:%M"):
						print('检测到%s文件中的密码不一样,优先选择最近修改的密码! 即' + OTH_ALL_ACCOUNT[key_oth]['UpdateTime'])
						ALL_ACCOUNT[key_oth] = OTH_ALL_ACCOUNT[key_oth]
	if saveAllPASS():
		print('合并成功!') 

def anaysisAdminPass(in_apass):
	'''
	获取MD5,在登陆时验证登录密码
	'''
	md = hashlib.md5()
	md.update(in_apass.encode('utf-8'))
	return md.hexdigest()
def login(in_apass = ''):
	'''
	登陆
	'''
	if in_apass == '':
		in_apass = getpass.win_getpass('输入密码:')
	global ADMINPASS
	#ADMINPASS = in_apass
	#print('登陆密码为'+str(ADMINPASS))
	#time.sleep(2)
	if anaysisAdminPass(in_apass) == ADMIN_ACCOUNT['Pass']:
		ADMINPASS = in_apass
		return True
	else:
		return False
def print_menu():
	'''
	打印菜单
	'''
	os.system('CLS')
	menu_text_dic = {'1':'查看密码本','2':'添加密码本','3':'修改密码本','4':'删除密码本','5':'合并密码本','6':'高级操作','7':'操作说明','0':'保存退出'}
	print('+'+''.center(WIN_WRITE-2,'-')+'+')
	print('|'+'欢迎使用个人账号管理工具'.center(WIN_WRITE-14,' ')+'|')
	print('|'+str(ADMIN_ACCOUNT['Account']).center(WIN_WRITE-2,' ')+'|')
	print('+'+''.center(WIN_WRITE-2,'-')+'+')

	for i in range(1,len(menu_text_dic)):
		item = menu_text_dic[str(i)]
		print('|'+(str(i)+'.'+item).center(WIN_WRITE-len(item)-2,' ')+'|')
	print('|'+(str(0)+'.'+menu_text_dic[str(0)]).center(WIN_WRITE-len(menu_text_dic[str(0)])-2,' ')+'|')
	print('+'+''.center(WIN_WRITE-2,'-')+'+')
	return input('你的选择是:')
def print_help(type = ''):
	'''
	打印操作文档
	'''
	if type == '':
		print('个人密码本管理系统v1.0.0')
		print('///------介绍文档------///:')
		print('这是一个个人开发的简易密码本系统\n'
			'成功运行必须安装python 3.5以上的环境\n'
			'*注意* 登录密码丢失,将不能找回,密码本也无法显示\n'
			'1.查看密码本\t查看所有的密码本,密码本就加密存储在这个文件末尾,切勿随意删除.\n'
			'2.添加密码本\t就简单的添加,没什么好说明的\n'
			'3.修改密码本\t\n'
			'4.删除密码本\t\n'
			'5.合并密码本\t 将两个同样的脚本中的不同的密码合并,必须知道后者密码本的登录密码.\n'
			'6.高级操作  \t该模式可以修改管理员的姓名和登录密码操作命令:\n'
			'\tupa -p xxx:修改登录密码为xxx\n'
			'\tupa -n xxx:修改管理员姓名为xxx\n'
			'\n///------快捷操作------///\n'
			'查找密码本----------- python xx.py -p密码 -s账号说明\n'
			'查看所有密码本------- python xx.py -p密码 -s\n'
			'添加密码本----------- python xx.py -p密码 -a账号说明/账号/密码\n'
			'删除密码本----------- python xx.py -p密码 -d账户说明\n'
			'更新密码本----------- python xx.py -p密码 -d账号说明/账号/密码\n'
			'合并密码本----------- python xx.py -p密码 -f文件名 -p2文件二密码\n'
			'操作说明------------- python -h\n')
	if type == '':
		pass
def adminOperation():
	'''
	以操作指令的方式进行
	例如: upa -n xxx 其中upa表示修改管理员信息的操作命令,-n表修改名称 xxx表示修改后的名称
	再例如 upa -p xxx 表示修改管理员密码
	'''
	while True:
		cmd = input('>>>').lstrip(' ').split(' ')
		if cmd[0] not in ('upa','exit','q','select','del','up'):
			print(cmd[0]+'不是内部命令')
			continue
		if cmd[0] == 'upa':		#更新管理员信息操作
			if len(cmd) !=3:
				print("未识别命令!")
				continue
			elif cmd[1] == '-n':
				ADMIN_ACCOUNT['Account'] = cmd[2]
				saveAllPASS()
			elif cmd[1] == '-p':
				global ADMINPASS
				global ALL_ACCOUNT

				o_apass = ADMINPASS
				tempAll_account = ALL_ACCOUNT.copy()
				
				ADMINPASS = cmd[2] 
				ADMIN_ACCOUNT['Pass'] = anaysisAdminPass(ADMINPASS)
				ADMIN_ACCOUNT['UpdateTime'] = datetime.datetime.now().strftime("%Y/%m/%d/%H:%M")
				try:
					for key in ALL_ACCOUNT.keys():
						#将密码本所有密码重新加密
						ALL_ACCOUNT[key]['Pass'] = encrypt(ADMINPASS,decrypt(o_apass,ALL_ACCOUNT[key]['Pass']))
						ALL_ACCOUNT[key]['OldPass'] = encrypt(ADMINPASS,decrypt(o_apass,ALL_ACCOUNT[key]['OldPass']))
				except Exception as e:
					print('修改失败!数据回滚.')
					#数据回滚
					ADMINPASS = o_apass
					ADMIN_ACCOUNT['Pass'] = anaysisAdminPass(o_apass)
					ALL_ACCOUNT = tempAll_account.copy()
					continue

				saveAllPASS()
				print("操作成功!")
			else:
				print("未识别命令")

			continue
		if cmd[0] == 'select':	#查找模式
			if len(cmd) != 2:
				print("未识别命令")
				continue

		elif cmd[0] in ('exit','q'):
			print('退出高级操作模式...')
			time.sleep(1)
			break
		else :
			print("未识别命令")
def add_to_16(text):
	'''
	补齐16位字符串
	'''
	
	#if len(text.encode('utf-8')) % 16:
	#	add = 16 - (len(text.encode('utf-8')) % 16)
	#else:
	#	add = 0
	add = 16 - (len(text.encode('utf-8')) % 16)
	text = text + ('\0' * add)
	return text.encode('utf-8')
def encrypt(key,text):
	'''
	AES加密,加密方式ECB
	参数:为字符串
	返回值:字符串
	'''
	key = add_to_16(key)
	text = add_to_16(text)
	cryptor = AES.new(key,AES.MODE_ECB)
	cipher_text = cryptor.encrypt(text) #加密返回值为bytes对象
	return cipher_text.hex()		#bytes对象转str
def decrypt(key,text):
	'''
	解密
	参数:为字符串
	返回值:字符串
	'''
	key = add_to_16(key)
	#text = add_to_16(text)
	cryptor = AES.new(key,AES.MODE_ECB)
	plain_text = cryptor.decrypt(BAscii.a2b_hex(text)) #解密返回值为bytes对象
	return bytes.decode(plain_text).rstrip('\0') #bytes转str
def main(login_pass = ''):
	#加载数据
	if readPASS() == 0 :
		print('读取失败,检查文件末尾是否存在密文！')
		time.sleep(2)
		return 
	if login(login_pass) is False:
		print('密码错误!')
		time.sleep(1)
		return
	while True:
		#打印菜单
		rep = str(print_menu())
		if rep == '0':		#退出
			break
		elif rep == '1':	#查看所有
			showSomePASS(ALL_ACCOUNT)
			while True:
				key_s = input("输入查找内容(退出请摁q):")
				if key_s == 'q':
					break
				if key_s == '':
					continue
				some_account = {}
				tempList = []
				pattern = '.*' + key_s + '.*'  #使用正则表达式模糊查询
				for key in ALL_ACCOUNT.keys():
					obj = re.findall(pattern, key)
					if len(obj)>0:
						tempList.extend(obj)
				#打印查找内容

				for k in tempList:
					some_account[k] = ALL_ACCOUNT[k].copy()
				showSomePASS(some_account)

		elif rep == '2':	#添加账号
			appendPASS()
			input("Arbitrary key return")
		elif rep == '3':	#修改账号
			if login() is False:
				print('密码错误!')
				time.sleep(2)
				continue
			update_pass()
		elif rep == '4':	#删除账号
			if login() is False:
				print('密码错误!.')
				time.sleep(2)
				continue
			delOnePASS("")
		elif rep == '5':	#合并操作
			str_input = input("输入文件合并过来的文件(退出请摁q):")  # 获取选择的文件名称
			#str_filename = Filedialog.askopenfilename(title='请选择一个文件', filetypes=[('脚本文本','.py'), ('文本文档','.txt'),('所有文件','*')], defaultextension='.py', multiple=True)
			if(len(str_filename)>0):
				mergePASS(str(str_filename[0]))
		elif rep == '6':
			adminOperation()
		elif rep == '7':
			print_help()
			input('任意键退出')
		else:
			continue
def main_2():
	'''
	带一个参数的入口函数h
	'''
	par_op1 = sys.argv[1][0:2]
	#加载数据
	if readPASS() == 0 :
		print('读取失败!')
		exit(1)

	if par_op1 not in ('-h','-p'):
		print("parameter error!")
		exit(1)
	if par_op1 == '-h':
		par_data1 = sys.argv[1].lstrip('-h')
		if par_data1 == '':
			print_help()
	if par_op1 == '-p':
		par_data1 = sys.argv[1].lstrip('-p')
		print(par_data1)
		main(par_data1)
def main_3():
	global MODE_OP
	MODE_OP = 1
	par_pass = sys.argv[1].lstrip('-p')		#密码
	par_op1 = sys.argv[1][0:2]		#操作指令1
	par_op2 = sys.argv[2][0:2]		#操作指令2
	if par_op1 not in ('-p',) or par_op2 not in('-s','-d','-a','-u'):
		print("parameter error!")
		exit(1)
	#加载数据
	if readPASS() == 0 :
		print('读取失败!')
		exit(1)
	#登陆
	if login(par_pass) is False:
		print('密码错误!')
		exit(1)
	if par_op2 == '-s':
		#查找操作
		par_data =sys.argv[2].lstrip('-s')	#操作数据
		if par_data == '':
			showSomePASS(ALL_ACCOUNT)
			return
		else:
			some_account = {}
			tempList = []
			pattern = '.*' + par_data + '.*'
			for key in ALL_ACCOUNT.keys():
				obj = re.findall(pattern, key)
				if len(obj)>0:
					tempList.extend(obj)
			for k in tempList:
				some_account[k] = ALL_ACCOUNT[k].copy()
			showSomePASS(some_account)
	if par_op2 == '-d':
		par_data =sys.argv[2].lstrip('-d')	#操作数据
		delOnePASS(par_data)
	if par_op2 == '-a':
		#添加操作
		par_data =sys.argv[2].lstrip('-a')	#操作数据
		in_data = par_data.split('/')
		appendPASS(in_data)
	if par_op2 == '-u':
		#更新操作
		par_data =sys.argv[2].lstrip('-u')	#操作数据
		up_data = par_data.split('/')
		update_pass(up_data[0],(up_data[1],up_data[2]))
def main_4():
	pass
if __name__ == '__main__':
	if len(sys.argv) == 1:
		main()
	elif len (sys.argv) == 2:
		main_2()
	elif len (sys.argv) == 3:
		main_3()
	elif len (sys.argv) == 4:
		main_4()
	else:
		print("parameter error!")


#e10adc3949ba59abbe56e057f20f883e（初始密码123456哈希值）
#已下是密码存储区域,切勿随意删除 
#-A-# Admin Griza.J e10adc3949ba59abbe56e057f20f883e 6c3e226b4d4795d518ab341b0824ec29 2020/01/21/20:37 2020/1/20/17:10
#-#-# 测试账号 admin 4f1eb44d4de6ae7e97d3800ee5370f1f 48aba5ebb6ad6e2a0bc793ef90aa8c1a 2022/05/20/02:26 2022/05/20/02:26
